//
//  OfficialTableViewCell.m
//  NewMyMusicAPP
//
//  Created by dlios on 15/6/19.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "OfficialTableViewCell.h"

@implementation OfficialTableViewCell

- (void)dealloc
{
    [_official release];
    [_description_label release];
    [_title_label release];
    [_posterPic release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createCell];
    }
    return self;
}

-(void)createCell
{
  
    
    self.posterPic = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, MYWIDTH, HEIGHT * 300)]autorelease];
    self.posterPic.backgroundColor = [UIColor whiteColor];
    
    self.posterPic.image = [UIImage imageNamed:@"default_discover_moment@3x.png"];
    [self.contentView addSubview:self.posterPic];
    
    UIView *myView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, MYWIDTH, HEIGHT * 300)]autorelease];
    myView.backgroundColor = [UIColor blackColor];
    myView.alpha = 0.2;
    [self.posterPic addSubview:myView];
    
    
    self.title_label = [[[UILabel alloc] init]autorelease];
    self.title_label.backgroundColor = [UIColor clearColor];

    [self.title_label setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];//加粗字体
    self.title_label.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.title_label];
    
    
    self.description_label = [[[UILabel alloc] initWithFrame:CGRectMake(WIDTH * 20, HEIGHT * 260, WIDTH * 300, HEIGHT * 20)]autorelease];
    self.description_label.backgroundColor = [UIColor clearColor];
    [self.description_label setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];//加粗字体

    self.description_label.textColor = [UIColor orangeColor];
    
    
    
    //收藏按钮

    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(WIDTH * 310, HEIGHT * 25, WIDTH * 30, WIDTH * 30);
    [self.button addTarget:self action:@selector(collect) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];
    
    

    
}

-(void)collect
{
    [[DataHandle shareHandleController] openDB];
   // [[DataHandle shareHandleController] dropCollectTable];
    CollectModel *collect = [[[CollectModel alloc] init]autorelease];
    collect.title = [NSString stringWithFormat:@"%@",self.official.title];
    collect.modelId = [NSString stringWithFormat:@"%@",self.official.modelId];
    collect.type = [NSString stringWithFormat:@"%@",self.official.type];
   // NSLog(@"asdasdasd = %@ %@ %@",collect.modelId,collect.type,collect.title);

    
    if ([DataHandle shareHandleController].monitorNetwork == YES) {
        if ([self.official.type isEqualToString:@"VIDEO"]||[self.official.type isEqualToString:@"PLAYLIST"]||[self.official.type isEqualToString:@"PROGRAM"]) {
            if (self.buer == NO) {
                [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heartup@3x.png"] forState:UIControlStateNormal];
                [[DataHandle shareHandleController] insertCollect:collect];
                self.buer = YES;
                // NSLog(@"添加收藏 NO  ==  id = %@",collect.modelId);
            }else
            {
                [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@3x.png"] forState:UIControlStateNormal];
                [[DataHandle shareHandleController] deleteTable:collect.modelId];
                self.buer = NO;
                
            }
        }else
        {
            UIAlertView *aler = [[UIAlertView alloc] initWithTitle:@"提示" message:@"此信息无法收藏" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
            [aler show];
        }
    }else
    {
        UIAlertView *aler = [[UIAlertView alloc] initWithTitle:@"提示" message:@"没有网络无法收藏" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
        [aler show];
    }
    
    
    
    


}

-(void)setOfficial:(OfficialModel *)official
{
    if (_official != official) {
        [_official release];
        _official = [official retain];
    }

   
    
    NSURL *url = [NSURL URLWithString:self.official.posterPic];
    [self.posterPic sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default_discover_moment@3x.png"]];
    
    
    
    self.description_label.text = self.official.description_label;

    if ([self.official.description_label isEqualToString:@""]||self.official.description_label == nil ||[self.official.description_label isEqualToString:@"(null)"] ) {
        self.title_label.frame =CGRectMake(WIDTH * 20, HEIGHT * 260, WIDTH * 330, HEIGHT * 20);
        self.title_label.text = self.official.title;
        self.description_label.text = @"";

        
    }else
    {
        self.title_label.frame =CGRectMake(WIDTH * 20, HEIGHT * 240, WIDTH * 330, HEIGHT *20);
        self.title_label.text = self.official.title;
        [self.contentView addSubview:self.description_label];
        
    }
  
    
    if (self.buer == YES) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heartup@3x.png"] forState:UIControlStateNormal];
        
        
    }else
    {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@2x.png"] forState:UIControlStateNormal];
        
    }
    
}









- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
